VHDL MOD和REM(转)

您所在的位置:网站首页 vhdl 求余数 VHDL MOD和REM(转)

VHDL MOD和REM(转)

2024-07-10 07:36| 来源: 网络整理| 查看: 265

mod(取模)and rem(取余)

VHDL has mod and rem. They return the same value if both arguments are positive.

but, they produce different results for negative inputs:

5 mod 3 = 2

(-5) mod 3 = 1

5 mod (-3) = -1

(-5) mod (-3) = -2

for mod, the result has the same sign with the first argument.

whereas

5 rem 3 = 2

(-5) rem 3 = -2

5 rem (-3) = 2

(-5) rem (-3) = -2

for rem,the result has the same sign with the second argument.

A rem B = A - ( A / B ) * B --余数运算符 利用操作数A决定结果的正负号

 

取余运算(a REM b)的符号与a相同,其绝对值小于b的绝对值。

 

A mod B = A - B * N --取模运算符 利用操作数B决定结果的正负号

 

取模运算(a MOD b)的符号与b相同,其绝对值小于b的绝对值。

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3